A magnetic encoder in the related art includes a magnetic body that is provided so as to be rotatable with a rotation shaft and that is formed in the shape of a disk, and a pair of Hall elements that is disposed in the vicinity of an outer peripheral surface of the magnetic body. On an outer peripheral side surface 11A of the magnetic body, a magnetic code is formed, in which N poles and S poles are alternately polarized. The pair of Hall elements detects magnetic fields generated by the magnetic code, and outputs pulse signals to an external unit. An A-phase pulse signal is output from one of the Hall elements. A B-phase pulse signal whose phase is 90 degrees different from that of the A-phase pulse signal is output from the other Hall element. By using the pulse signals, a rotation direction of the rotation shaft or the number of rotations can be detected (for example, Patent Document 1).
Patent Document 1: Japanese Unexamined Patent Application Publication No. 9-243399